<template>
    <div>
        <el-dialog title="设置用户等级" :visible="true" width="600px" :modal-append-to-body="false"
            :close-on-click-modal="false" @close="handleClose">
            <el-form id="forms" ref="forms" :rules="rulesModel" :model="form" label-width="100px">
                <el-form-item label="等级" prop="userLevel">
                    <el-input v-model="form.userLevel" type="number" :disabled="form.userLevel" placeholder="请输入等级" />
                </el-form-item>
                <el-form-item label="等级名称" prop="userName">
                    <el-input v-model="form.userName" placeholder="请输入等级名称" />
                </el-form-item>
                <el-form-item label="管理津贴级差" prop="fwRate">
                    <el-input v-model="form.fwRate" type="number" placeholder="请输入管理津贴级差" />
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button :loading="buttonLoading" type="primary" @click="submit()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { setUserLevelConfig } from "@/api/sysconfig.js";
export default {
    props: {
        info: {
            default: {},
            type: Object
        },
    },
    data() {
        return {
            form: {}, // 详情实体
            rulesModel: {
                power: [
                    { required: true, message: '请输入数量', trigger: 'blur' }
                ],
            },
            buttonLoading: false,
        }
    },

    mounted() {
        this.setForm();
    },
    methods: {
        /**关闭弹窗 */
        handleClose() {
            this.$parent.modalStatus = 0
        },
        /**表单参数初始化 */
        setForm() {
            if (this.info) {
                this.form = this.info
            } else {
                this.form = {
                    userLevel: 0,
                    userName: '',
                    fwRate: 0,
                };
            }

        },
        /**（提交） */
        async submit() {
            try {
                try {
                    await this.$refs['forms'].validate()
                } catch (e) {
                    console.log(e)
                    return
                }
                const { success, msg } = await setUserLevelConfig(this.form)
                if (success) {
                    this.handleClose();
                }
                this.$message({
                    message: msg,
                    type: success ? 'success' : 'error'
                })
            } catch (e) {
                // 取消
                console.log(e)
            }
        },
    }
}
</script>

<style lang="scss" scoped>
.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
}
</style>